/*
 * @Author: 陈 娇
 * @Date: 2021-04-13 19:36:05
 * @LastEditTime: 2021-06-04 10:29:56
 * @LastEditors: Please set LastEditors
 * @Description: 通用设置数据封装
 * @FilePath: \ebc-admin\src\views\basics\GeneralSet\config\general.config.js
 */

function transformParams(editList, detail, isRed) {
  editList.forEach(item => {
    if (item.transform) {
      item.transform(detail);
    } else {
      item.value = detail[item.key]
    }
    if (isRed && !item.disabled) item.disabled = true;
  })
}

// 表单项
export const itemList = [
  { label: '网络设置：', value: 'ebc.benwu.cn', disabled: true },
  { label: '邮箱设置：', value: 'ebc@benwu.cn', disabled: true },
  { label: '电话设置：', value: '400-488-488', disabled: true }
]

export const festiveClumen = [
  { prop: 'id', label: '节日编号' },
  { prop: 'holiday', label: '节日名称' },
  { prop: 'modifierName', label: '修改人', isTemplate: true },
  { prop: 'gmtModified', label: '修改时间' },
  { prop: 'operate', label: '操作', isTemplate: true }
]
export const selects = [

]
// 操作弹窗数据
export function createList(list) {
  const editList = [
    { type: 'select', key: 'holiday', label: '节日名称:', placeholder: '请输入', options: list }
  ]
  return editList
}

// 协议页面-搜索
export const searchs = [
  { type: 'input', key: 'name', value: '', placeholder: '协议名称' }
]

// 协议设置数据
export const listHedar = [
  { prop: 'settingCode', label: '协议政策编号' },
  { prop: 'settingName', label: '协议名称' },
  { prop: 'modifierName', label: '修改人' },
  { prop: 'gmtModified', label: '修改时间' },
  { prop: 'operate', label: '操作', isTemplate: true, fixed: 'right' }
]
// 添加协议设置弹窗数据封装
export const protocolEditList = [
  { type: 'input', key: 'settingName', label: '协议政策名称:', placeholder: '请输入', disabled: false },
  { type: 'slot', name: 'text', key: 'settingContent', label: '协议政策内容:', placeholder: '', disabled: false }
]
// 短信平台设置
export function shortData2(detail) {
  const listHedar = [
    { prop: 'id', label: '短信平台编号' },
    { prop: 'platformName', label: '平台名称' },
    { prop: 'platformDomain', label: '平台域名' },
    { prop: 'accessId', label: '访问id' },
    { prop: 'accessKey', label: '访问秘钥' },
    { prop: 'connectTimeout', label: '连接超时' },
    { prop: 'readTimeout', label: '读取超时' },
    { prop: 'modifierName', label: '修改人' },
    { prop: 'gmtModified', label: '修改时间' },
    { prop: 'operate', label: '操作', isTemplate: true }
  ]
  const searchs = [
    { type: 'input', key: 'platform', value: '', placeholder: '短信平台' }
  ]
  return {
    listHedar, searchs
  }
}
export function createShort2Edit(detail) {
  const editList = [
    { type: 'input', key: 'platformName', label: '平台名称：', value: '', have: true },
    { type: 'input', key: 'platformDomain', label: '平台域名：', value: '', have: true },
    { type: 'input', key: 'accessId', label: '访问id：: ', value: '', have: true },
    { type: 'input', key: 'accessKey', label: '访问秘钥： ', value: '', have: true },
    { type: 'input', key: 'connectTimeout', label: '连接超时： ', value: '', have: true },
    { type: 'input', key: 'readTimeout', label: '读取超时： ', value: '', have: true }
  ]
  if (detail) {
    editList.unshift({ type: 'input', key: 'id', label: '短信模板编号: ', disabled: true, value: detail.id })
    transformParams(editList, detail);
  }
  return editList;
}

// 短信模板设置
export function createShortEdit(detail, isRed, list) {
  const editList = [
    { 
      type: 'select', 
      key: 'tempType', 
      label: '短信类型：', 
      value: '', 
      options: [
        { title: '验证码', value: 0 },
        { title: '短信通知', value: 1 },
        { title: '推广短信', value: 2 },
        {title: '国际/港澳台消息', value: 3 }
      ],
      have: true 
    },
    { type: 'textarea', key: 'tempContent', label: '模板内容： ', value: '', have: true, maxlength: 500, showWordLimit: true, tip: '证码：${code}、姓名：${real_name}、尊称${title_name};变量不能为email,mobile,id,ip,nick,site' },
    { type: 'textarea', key: 'tempRemark', label: '申请说明： ', value: '', have: true, maxlength: 100, showWordLimit: true }
  ]
  if (detail) {
    editList.unshift(
      { type: 'input', key: 'id', label: '短信模板编号: ', disabled: true, value: '' },
      { type: 'select', key: 'platformId', label: '短信平台：', value: '', options: list, have: true, disabled: true },
      { type: 'input', key: 'tempCode', label: '模板CODE: ', disabled: true, value: '' },
      { type: 'input', key: 'tempName', label: '模板名称：', value: '', have: true },
    )
    if (isRed && detail.statusAudit == 2) {
      editList.push({ type: 'textarea', key: 'reason', label: '失败原因: ', disabled: true, value: '' })
    }
    transformParams(editList, detail, isRed);
  } else {
    editList.unshift(
      { type: 'input', key: 'tempName', label: '模板名称：', value: '', have: true },
      { type: 'select', key: 'platformId', label: '短信平台：', value: '', options: list, have: true }
    )
  }
  return editList;
}
export function shortData(detail) {
  const searchs = [
    { type: 'input', key: 'introduce', value: '', placeholder: '模板名称' }
  ]
  return { searchs }
}
export function createShortList(list) {
  const listHedar = [
    { prop: 'id', label: '短信模板编号' },
    { prop: 'tempName', label: '模板名称' },
    {
      prop: 'platformId', label: '短信平台',
      show(row) {
        return list.find(item => item.value == row.platformId).title;
      }
    },
    { prop: 'tempCode', label: '模板CODE' },
    {
      prop: 'tempType',
      label: '短信类型',
      show: { 0: '验证码', 1: '短信通知', 2: '推广短信', 3: '国际/港澳台消息' }
    },
    {
      prop: 'statusAudit', label: '审核状态',
      show: { 0: '审核中', 1: '审核通过', 2: '审核失败，请在返回参数Reason中查看审核失败原因' }
    },
    { prop: 'modifierName', label: '修改人' },
    { prop: 'gmtModified', label: '修改时间' },
    { prop: 'operate', label: '操作', isTemplate: true }
  ]
  return listHedar;
}
